options compress=YES;
libname manasi ''; 
libname earn ''; 

* MERGE PARENTAL EARNINGS INTO CHILDRENS' RECORDS;

* USE ONLY HUN AND PAN FROM PARENTS' SSR RECORDS;
data manasi.ssr_parents_hunpan;
	set manasi.ssr_parents_full(keep=hun pan toa mft dob dobyy dod sex);
	if pan='*00000000' then delete;
run;

* ELIMINATE DUPLICATES BY HUN AND PAN AND SORT ;
proc sort data=manasi.ssr_parents_hunpan out=manasi.ssr_parents_hunpan nodupkey;
	by pan hun;
run;

* SORT PARENT EARNINGS RECORDS ;
data earn.par_earn;
	set earn.manasi_earn(keep=ssn sex dob_: dod_: sum_earn:);
run;

proc sort data=earn.par_earn out=earn.par_earn;
	by ssn;
run;

* MERGE IN PARENT EARNINGS RECORDS ;
data earn.par_earn_hunmerge;
	merge 	
			manasi.ssr_parents_hunpan 
			(rename=(pan=ssn dob=dob_ssr dobyy=dobyy_ssr sex=sex_ssr toa=toa_ssr mft=mft_ssr dod=dod_ssr) 
				in=fromssrx)

			earn.par_earn 
			(in=fromearnx);

	by ssn; 
	fromssr = fromssrx;
	fromearn = fromearnx;
run;

proc tabulate data=earn.par_earn_hunmerge;
	class fromearn fromssr;
	table fromearn, fromssr;
run;

* MERGE IN VARIABLE INDICATING WHETHER PARENT WAS IN HOUSEHOLD AT ANY TIME
BETWEEN 2002 AND 2006 (GENERAL TREATMENT PERIOD);
proc sort data=earn.par_earn_hunmerge out=earn.par_earn_hunmerge;
	by hun ssn;
run;

data earn.par_earn_hunmerge;
	merge 	
			earn.par_earn_hunmerge 

			manasi.ssr_parents_estpdonly_wide
			(rename=(pan=ssn) keep=hun pan inhh0206);

	by hun ssn; 
run;

proc sort data=earn.par_earn_hunmerge out=earn.par_earn_hunmerge;
	by hun;
run;

data earn.par_earn_hunmerge_wide;
	set earn.par_earn_hunmerge;
	par_id + 1;
	by hun;
	if first.hun then par_id=1;
run;

data earn.par_earn_hunmerge_wide;
	set earn.par_earn_hunmerge_wide;
	if ssn='*00000000' then delete;
run;

proc means data=earn.par_earn_hunmerge_wide noprint;
	by hun;
	var par_id;
	output out=earn.par_earn_parid max(par_id)=max_parid;
run;

proc means mean median min max p90 p95 p99 data=earn.par_earn_parid;
	var max_parid;
run;

* COLLAPSE TO HUN LEVEL TO GET ONE RECORD FOR EACH KID;
data earn.par_earn_hunmerge_wide;
	set earn.par_earn_hunmerge_wide;
	by hun;

	keep 	hun 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7
			inhh0206_1-inhh0206_7
			sum_earns1_1-sum_earns1_7
			sum_earns2_1-sum_earns2_7
			sum_earns3_1-sum_earns3_7
			sum_earns4_1-sum_earns4_7
			sum_earns5_1-sum_earns5_7
			sum_earns6_1-sum_earns6_7
			sum_earns7_1-sum_earns7_7
			sum_earns8_1-sum_earns8_7
			sum_earns9_1-sum_earns9_7
			sum_earns10_1-sum_earns10_7
			sum_earns11_1-sum_earns11_7
			sum_earns12_1-sum_earns12_7
			sum_earns13_1-sum_earns13_7
			sum_earns14_1-sum_earns14_7
			sum_earns15_1-sum_earns15_7
			sum_earns16_1-sum_earns16_7
			sum_earns17_1-sum_earns17_7
			sum_earns18_1-sum_earns18_7
			sum_earns19_1-sum_earns19_7
			sum_earns20_1-sum_earns20_7
			sum_earns21_1-sum_earns21_7
			sum_earns22_1-sum_earns22_7
			sum_earns23_1-sum_earns23_7
			sum_earns24_1-sum_earns24_7
			sum_earns25_1-sum_earns25_7
			sum_earns26_1-sum_earns26_7
			sum_earns27_1-sum_earns27_7
			sum_earns28_1-sum_earns28_7
			sum_earns29_1-sum_earns29_7
			sum_earns30_1-sum_earns30_7
			sum_earns31_1-sum_earns31_7
			sum_earns32_1-sum_earns32_7
			sum_earns33_1-sum_earns33_7
			sum_earns34_1-sum_earns34_7
			sum_earns35_1-sum_earns35_7
			sum_earns36_1-sum_earns36_7
			sum_earns37_1-sum_earns37_7
			sum_earns38_1-sum_earns38_7
			sum_earns39_1-sum_earns39_7
			sum_earns40_1-sum_earns40_7
			sum_earns41_1-sum_earns41_7
			sum_earns42_1-sum_earns42_7
			sum_earns43_1-sum_earns43_7
			sum_earns44_1-sum_earns44_7
			sum_earns45_1-sum_earns45_7
			sum_earns46_1-sum_earns46_7
			sum_earns47_1-sum_earns47_7
			sum_earns48_1-sum_earns48_7
			sum_earns49_1-sum_earns49_7
			sum_earns50_1-sum_earns50_7
			sum_earns51_1-sum_earns51_7
			sum_earns52_1-sum_earns52_7
			sum_earns53_1-sum_earns53_7
			sum_earns54_1-sum_earns54_7
			sum_earns55_1-sum_earns55_7
			sum_earns56_1-sum_earns56_7
			sum_earns57_1-sum_earns57_7
			sum_earns58_1-sum_earns58_7
			sum_earns59_1-sum_earns59_7
			sum_earns60_1-sum_earns60_7
			sum_earns61_1-sum_earns61_7
			;
			

	retain 	 
			ssn1-ssn7 
			toa_ssr1-toa_ssr7 
			mft_ssr1-mft_ssr7
			dob_ssr1-dob_ssr7
			dobyy_ssr1-dobyy_ssr7 
			dod_ssr1-dod_ssr7 
			sex_ssr1-sex_ssr7
			inhh0206_1-inhh0206_7
			sum_earns1_1-sum_earns1_7
			sum_earns2_1-sum_earns2_7
			sum_earns3_1-sum_earns3_7
			sum_earns4_1-sum_earns4_7
			sum_earns5_1-sum_earns5_7
			sum_earns6_1-sum_earns6_7
			sum_earns7_1-sum_earns7_7
			sum_earns8_1-sum_earns8_7
			sum_earns9_1-sum_earns9_7
			sum_earns10_1-sum_earns10_7
			sum_earns11_1-sum_earns11_7
			sum_earns12_1-sum_earns12_7
			sum_earns13_1-sum_earns13_7
			sum_earns14_1-sum_earns14_7
			sum_earns15_1-sum_earns15_7
			sum_earns16_1-sum_earns16_7
			sum_earns17_1-sum_earns17_7
			sum_earns18_1-sum_earns18_7
			sum_earns19_1-sum_earns19_7
			sum_earns20_1-sum_earns20_7
			sum_earns21_1-sum_earns21_7
			sum_earns22_1-sum_earns22_7
			sum_earns23_1-sum_earns23_7
			sum_earns24_1-sum_earns24_7
			sum_earns25_1-sum_earns25_7
			sum_earns26_1-sum_earns26_7
			sum_earns27_1-sum_earns27_7
			sum_earns28_1-sum_earns28_7
			sum_earns29_1-sum_earns29_7
			sum_earns30_1-sum_earns30_7
			sum_earns31_1-sum_earns31_7
			sum_earns32_1-sum_earns32_7
			sum_earns33_1-sum_earns33_7
			sum_earns34_1-sum_earns34_7
			sum_earns35_1-sum_earns35_7
			sum_earns36_1-sum_earns36_7
			sum_earns37_1-sum_earns37_7
			sum_earns38_1-sum_earns38_7
			sum_earns39_1-sum_earns39_7
			sum_earns40_1-sum_earns40_7
			sum_earns41_1-sum_earns41_7
			sum_earns42_1-sum_earns42_7
			sum_earns43_1-sum_earns43_7
			sum_earns44_1-sum_earns44_7
			sum_earns45_1-sum_earns45_7
			sum_earns46_1-sum_earns46_7
			sum_earns47_1-sum_earns47_7
			sum_earns48_1-sum_earns48_7
			sum_earns49_1-sum_earns49_7
			sum_earns50_1-sum_earns50_7
			sum_earns51_1-sum_earns51_7
			sum_earns52_1-sum_earns52_7
			sum_earns53_1-sum_earns53_7
			sum_earns54_1-sum_earns54_7
			sum_earns55_1-sum_earns55_7
			sum_earns56_1-sum_earns56_7
			sum_earns57_1-sum_earns57_7
			sum_earns58_1-sum_earns58_7
			sum_earns59_1-sum_earns59_7
			sum_earns60_1-sum_earns60_7
			sum_earns61_1-sum_earns61_7
			;

	array	assn(1:7) 			ssn1-ssn7 ; 
	array	atoa_ssr(1:7) $ 2	toa_ssr1-toa_ssr7 ;
	array	amft_ssr(1:7) $ 2	mft_ssr1-mft_ssr7;
	array	adob_ssr(1:7)		dob_ssr1-dob_ssr7;
	array	adobyy_ssr(1:7)		dobyy_ssr1-dobyy_ssr7; 
	array	adod_ssr(1:7)		dod_ssr1-dod_ssr7 ;
	array	asex_ssr(1:7) $ 2	sex_ssr1-sex_ssr7;
	array 	ainhh0206(1:7)		inhh0206_1-inhh0206_7;
	array	asum_earns1(1:7)	sum_earns1_1-sum_earns1_7;
	array	asum_earns2(1:7)	sum_earns2_1-sum_earns2_7;
	array	asum_earns3(1:7)	sum_earns3_1-sum_earns3_7;
	array	asum_earns4(1:7)	sum_earns4_1-sum_earns4_7;
	array	asum_earns5(1:7)	sum_earns5_1-sum_earns5_7;
	array	asum_earns6(1:7)	sum_earns6_1-sum_earns6_7;
	array	asum_earns7(1:7)	sum_earns7_1-sum_earns7_7;
	array	asum_earns8(1:7)	sum_earns8_1-sum_earns8_7;
	array	asum_earns9(1:7)	sum_earns9_1-sum_earns9_7;
	array	asum_earns10(1:7)	sum_earns10_1-sum_earns10_7;
	array	asum_earns11(1:7)	sum_earns11_1-sum_earns11_7;
	array	asum_earns12(1:7)	sum_earns12_1-sum_earns12_7;
	array	asum_earns13(1:7)	sum_earns13_1-sum_earns13_7;
	array	asum_earns14(1:7)	sum_earns14_1-sum_earns14_7;
	array	asum_earns15(1:7)	sum_earns15_1-sum_earns15_7;
	array	asum_earns16(1:7)	sum_earns16_1-sum_earns16_7;
	array	asum_earns17(1:7)		sum_earns17_1-sum_earns17_7;
	array	asum_earns18(1:7)		sum_earns18_1-sum_earns18_7;
	array	asum_earns19(1:7)		sum_earns19_1-sum_earns19_7;
	array	asum_earns20(1:7)		sum_earns20_1-sum_earns20_7;
	array	asum_earns21(1:7)		sum_earns21_1-sum_earns21_7;
	array	asum_earns22(1:7)		sum_earns22_1-sum_earns22_7;
	array	asum_earns23(1:7)		sum_earns23_1-sum_earns23_7;
	array	asum_earns24(1:7)		sum_earns24_1-sum_earns24_7;
	array	asum_earns25(1:7)		sum_earns25_1-sum_earns25_7;
	array	asum_earns26(1:7)		sum_earns26_1-sum_earns26_7;
	array	asum_earns27(1:7)		sum_earns27_1-sum_earns27_7;
	array	asum_earns28(1:7)		sum_earns28_1-sum_earns28_7;
	array	asum_earns29(1:7)		sum_earns29_1-sum_earns29_7;
	array	asum_earns30(1:7)		sum_earns30_1-sum_earns30_7;
	array	asum_earns31(1:7)		sum_earns31_1-sum_earns31_7;
	array	asum_earns32(1:7)		sum_earns32_1-sum_earns32_7;
	array	asum_earns33(1:7)		sum_earns33_1-sum_earns33_7;
	array	asum_earns34(1:7)		sum_earns34_1-sum_earns34_7;
	array	asum_earns35(1:7)		sum_earns35_1-sum_earns35_7;
	array	asum_earns36(1:7)		sum_earns36_1-sum_earns36_7;
	array	asum_earns37(1:7)		sum_earns37_1-sum_earns37_7;
	array	asum_earns38(1:7)		sum_earns38_1-sum_earns38_7;
	array	asum_earns39(1:7)		sum_earns39_1-sum_earns39_7;
	array	asum_earns40(1:7)		sum_earns40_1-sum_earns40_7;
	array	asum_earns41(1:7)		sum_earns41_1-sum_earns41_7;
	array	asum_earns42(1:7)		sum_earns42_1-sum_earns42_7;
	array	asum_earns43(1:7)		sum_earns43_1-sum_earns43_7;
	array	asum_earns44(1:7)		sum_earns44_1-sum_earns44_7;
	array	asum_earns45(1:7)		sum_earns45_1-sum_earns45_7;
	array	asum_earns46(1:7)		sum_earns46_1-sum_earns46_7;
	array	asum_earns47(1:7)		sum_earns47_1-sum_earns47_7;
	array	asum_earns48(1:7)		sum_earns48_1-sum_earns48_7;
	array	asum_earns49(1:7)		sum_earns49_1-sum_earns49_7;
	array	asum_earns50(1:7)		sum_earns50_1-sum_earns50_7;
	array	asum_earns51(1:7)		sum_earns51_1-sum_earns51_7;
	array	asum_earns52(1:7)		sum_earns52_1-sum_earns52_7;
	array	asum_earns53(1:7)		sum_earns53_1-sum_earns53_7;
	array	asum_earns54(1:7)		sum_earns54_1-sum_earns54_7;
	array	asum_earns55(1:7)		sum_earns55_1-sum_earns55_7;
	array	asum_earns56(1:7)		sum_earns56_1-sum_earns56_7;
	array	asum_earns57(1:7)		sum_earns57_1-sum_earns57_7;
	array	asum_earns58(1:7)		sum_earns58_1-sum_earns58_7;
	array	asum_earns59(1:7)		sum_earns59_1-sum_earns59_7;
	array	asum_earns60(1:7)		sum_earns60_1-sum_earns60_7;
	array	asum_earns61(1:7)		sum_earns61_1-sum_earns61_7;

	if first.hun then
	do;
		do i=1 to 7;
			assn(i) 		=.;	
			atoa_ssr(i)		="";
			amft_ssr(i)		="";	
			adob_ssr(i)		=.;	
			adobyy_ssr(i)	=.;		
			adod_ssr(i)		=.;	
			asex_ssr(i)		="";
			ainhh0206(i)	=.;
			asum_earns1(i)	=.;
			asum_earns2(i)	=.;
			asum_earns3(i)	=.;
			asum_earns4(i)	=.;
			asum_earns5(i)	=.;
			asum_earns6(i)	=.;
			asum_earns7(i)	=.;
			asum_earns8(i)	=.;
			asum_earns9(i)	=.;
			asum_earns10(i)	=.;
			asum_earns11(i)	=.;
			asum_earns12(i)	=.;
			asum_earns13(i)	=.;
			asum_earns14(i)	=.;
			asum_earns15(i)	=.;
			asum_earns16(i)	=.;
			asum_earns17(i)	=.;
			asum_earns18(i)	=.;
			asum_earns19(i)	=.;
			asum_earns20(i)	=.;
			asum_earns21(i)	=.;
			asum_earns22(i)	=.;
			asum_earns23(i)	=.;
			asum_earns24(i)	=.;
			asum_earns25(i)	=.;
			asum_earns26(i)	=.;
			asum_earns27(i)	=.;
			asum_earns28(i)	=.;
			asum_earns29(i)	=.;
			asum_earns30(i)	=.;
			asum_earns31(i)	=.;
			asum_earns32(i)	=.;
			asum_earns33(i)	=.;
			asum_earns34(i)	=.;
			asum_earns35(i)	=.;
			asum_earns36(i)	=.;
			asum_earns37(i)	=.;
			asum_earns38(i)	=.;
			asum_earns39(i)	=.;
			asum_earns40(i)	=.;
			asum_earns41(i)	=.;
			asum_earns42(i)	=.;
			asum_earns43(i)	=.;
			asum_earns44(i)	=.;
			asum_earns45(i)	=.;
			asum_earns46(i)	=.;
			asum_earns47(i)	=.;
			asum_earns48(i)	=.;
			asum_earns49(i)	=.;
			asum_earns50(i)	=.;
			asum_earns51(i)	=.;
			asum_earns52(i)	=.;
			asum_earns53(i)	=.;
			asum_earns54(i)	=.;
			asum_earns55(i)	=.;
			asum_earns56(i)	=.;
			asum_earns57(i)	=.;
			asum_earns58(i)	=.;
			asum_earns59(i)	=.;
			asum_earns60(i)	=.;
			asum_earns61(i)	=.;
		end;
	end;

	assn(par_id) 		= ssn ;	
	atoa_ssr(par_id)	= toa_ssr ;
	amft_ssr(par_id)	= mft_ssr ;	
	adob_ssr(par_id)	= dob_ssr ;	
	adobyy_ssr(par_id)	= dobyy_ssr ;		
	adod_ssr(par_id)	= dod_ssr ;	
	asex_ssr(par_id)	= sex_ssr;
	ainhh0206(par_id)		= inhh0206;
	asum_earns1(par_id)		= sum_earns1;	
	asum_earns2(par_id)		= sum_earns2;	
	asum_earns3(par_id)		= sum_earns3;	
	asum_earns4(par_id)		= sum_earns4;	
	asum_earns5(par_id)		= sum_earns5;	
	asum_earns6(par_id)		= sum_earns6;	
	asum_earns7(par_id)		= sum_earns7;	
	asum_earns8(par_id)		= sum_earns8;	
	asum_earns9(par_id)		= sum_earns9;	
	asum_earns10(par_id)	= sum_earns10;	
	asum_earns11(par_id)	= sum_earns11;	
	asum_earns12(par_id)	= sum_earns12;	
	asum_earns13(par_id)	= sum_earns13;	
	asum_earns14(par_id)	= sum_earns14;	
	asum_earns15(par_id)	= sum_earns15;	
	asum_earns16(par_id)	= sum_earns16;	
	asum_earns17(par_id)	= sum_earns17;	
	asum_earns18(par_id)	= sum_earns18;	
	asum_earns19(par_id)	= sum_earns19;	
	asum_earns20(par_id)	= sum_earns20;	
	asum_earns21(par_id)	= sum_earns21;	
	asum_earns22(par_id)	= sum_earns22;	
	asum_earns23(par_id)	= sum_earns23;	
	asum_earns24(par_id)	= sum_earns24;	
	asum_earns25(par_id)	= sum_earns25;	
	asum_earns26(par_id)	= sum_earns26;
	asum_earns27(par_id)	= sum_earns27;	
	asum_earns28(par_id)	= sum_earns28;	
	asum_earns29(par_id)	= sum_earns29;		
	asum_earns30(par_id)	= sum_earns30;
	asum_earns31(par_id)	= sum_earns31;
	asum_earns32(par_id)	= sum_earns32;
	asum_earns33(par_id)	= sum_earns33;	
	asum_earns34(par_id)	= sum_earns34;
	asum_earns35(par_id)	= sum_earns35;
	asum_earns36(par_id)	= sum_earns36;
	asum_earns37(par_id)	= sum_earns37;
	asum_earns38(par_id)	= sum_earns38;
	asum_earns39(par_id)	= sum_earns39;
	asum_earns40(par_id)	= sum_earns40;
	asum_earns41(par_id)	= sum_earns41;
	asum_earns42(par_id)	= sum_earns42;
	asum_earns43(par_id)	= sum_earns43;
	asum_earns44(par_id)	= sum_earns44;
	asum_earns45(par_id)	= sum_earns45;
	asum_earns46(par_id)	= sum_earns46;
	asum_earns47(par_id)	= sum_earns47;
	asum_earns48(par_id)	= sum_earns48;
	asum_earns49(par_id)	= sum_earns49;
	asum_earns50(par_id)	= sum_earns50;
	asum_earns51(par_id)	= sum_earns51;
	asum_earns52(par_id)	= sum_earns52;
	asum_earns53(par_id)	= sum_earns53;
	asum_earns54(par_id)	= sum_earns54;
	asum_earns55(par_id)	= sum_earns55;
	asum_earns56(par_id)	= sum_earns56;
	asum_earns57(par_id)	= sum_earns57;
	asum_earns58(par_id)	= sum_earns58;
	asum_earns59(par_id)	= sum_earns59;
	asum_earns60(par_id)	= sum_earns60;
	asum_earns61(par_id)	= sum_earns61;

	if last.hun then output;

run;

data earn.par_earn_hunmerge_wide;
	set earn.par_earn_hunmerge_wide;

	* Create macro for summary earnings variable ;
	%macro sumearn(year,no);
		n_hhearns_&year.=SUM(OF sum_earns&no._:);

		n_hhearns0206_&year.=0;
		if inhh0206_1=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._1;
		if inhh0206_2=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._2;
		if inhh0206_3=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._3;
		if inhh0206_4=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._4;
		if inhh0206_5=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._5;
		if inhh0206_6=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._6;
		if inhh0206_7=1 then n_hhearns0206_&year.=n_hhearns0206_&year.+sum_earns&no._7;
	%mend sumearn;

	%sumearn(1951,1);
	%sumearn(1952,2);
	%sumearn(1953,3);
	%sumearn(1954,4);
	%sumearn(1955,5);
	%sumearn(1956,6);
	%sumearn(1957,7);
	%sumearn(1958,8);
	%sumearn(1959,9);
	%sumearn(1960,10);
	%sumearn(1961,11);
	%sumearn(1962,12);
	%sumearn(1963,13);
	%sumearn(1964,14);
	%sumearn(1965,15);
	%sumearn(1966,16);
	%sumearn(1967,17);
	%sumearn(1968,18);
	%sumearn(1969,19);
	%sumearn(1970,20);
	%sumearn(1971,21);
	%sumearn(1972,22);
	%sumearn(1973,23);
	%sumearn(1974,24);
	%sumearn(1975,25);
	%sumearn(1976,26);
	%sumearn(1977,27);
	%sumearn(1978,28);
	%sumearn(1979,29);
	%sumearn(1980,30);
	%sumearn(1981,31);
	%sumearn(1982,32);
	%sumearn(1983,33);
	%sumearn(1984,34);
	%sumearn(1985,35);
	%sumearn(1986,36);
	%sumearn(1987,37);
	%sumearn(1988,38);
	%sumearn(1989,39);
	%sumearn(1990,40);
	%sumearn(1991,41);
	%sumearn(1992,42);
	%sumearn(1993,43);
	%sumearn(1994,44);
	%sumearn(1995,45);
	%sumearn(1996,46);
	%sumearn(1997,47);
	%sumearn(1998,48);
	%sumearn(1999,49);
	%sumearn(2000,50);
	%sumearn(2001,51);
	%sumearn(2002,52);
	%sumearn(2003,53);
	%sumearn(2004,54);
	%sumearn(2005,55);
	%sumearn(2006,56);
	%sumearn(2007,57);
	%sumearn(2008,58);
	%sumearn(2009,59);
	%sumearn(2010,60);
	%sumearn(2011,61);

	%macro dropvar(var);
		drop &var.3-&var.7;
	%mend dropvar;

	%dropvar(ssn);
	%dropvar(toa_ssr);
	%dropvar(mft_ssr);
	%dropvar(dob_ssr);
	%dropvar(dobyy_ssr);
	%dropvar(dod_ssr);
	%dropvar(sex_ssr);

	%macro dropearns(no);
		drop sum_earns&no._1-sum_earns&no._7;
	%mend dropearns;

	%dropearns(1);
	%dropearns(2);
	%dropearns(3);
	%dropearns(4);
	%dropearns(5);
	%dropearns(6);
	%dropearns(7);
	%dropearns(8);
	%dropearns(9);
	%dropearns(10);
	%dropearns(11);
	%dropearns(12);
	%dropearns(13);
	%dropearns(14);
	%dropearns(15);
	%dropearns(16);
	%dropearns(17);
	%dropearns(18);
	%dropearns(19);
	%dropearns(20);
	%dropearns(21);
	%dropearns(22);
	%dropearns(23);
	%dropearns(24);
	%dropearns(25);
	%dropearns(26);
	%dropearns(27);
	%dropearns(28);
	%dropearns(29);
	%dropearns(30);
	%dropearns(31);
	%dropearns(32);
	%dropearns(33);
	%dropearns(34);
	%dropearns(35);
	%dropearns(36);
	%dropearns(37);
	%dropearns(38);
	%dropearns(39);
	%dropearns(40);
	%dropearns(41);
	%dropearns(42);
	%dropearns(43);
	%dropearns(44);
	%dropearns(45);
	%dropearns(46);
	%dropearns(47);
	%dropearns(48);
	%dropearns(49);
	%dropearns(50);
	%dropearns(51);
	%dropearns(52);
	%dropearns(53);
	%dropearns(54);
	%dropearns(55);
	%dropearns(56);
	%dropearns(57);
	%dropearns(58);
	%dropearns(59);
	%dropearns(60);
	%dropearns(61);

	%macro rename(var,no);
		rename &var.&no.=par&no._&var.;
	%mend rename;

	%rename(ssn,1);
	%rename(ssn,2);
	%rename(toa_ssr,1);
	%rename(toa_ssr,2);
	%rename(mft_ssr,1);
	%rename(mft_ssr,2);
	%rename(dob_ssr,1);
	%rename(dob_ssr,2);
	%rename(dobyy_ssr,1);
	%rename(dobyy_ssr,2);
	%rename(dod_ssr,1);
	%rename(dod_ssr,2);
	%rename(sex_ssr,1);
	%rename(sex_ssr,2);

run;

* INFLATE EARNINGS;
data earn.par_earn_hunmerge_wide;
	set earn.par_earn_hunmerge_wide;

	* Inflate earnings to 2012 dollars;
	n_cpi_1951=8.85;
	n_cpi_1952=8.69;
	n_cpi_1953=8.62;
	n_cpi_1954=8.56;
	n_cpi_1955=8.59;
	n_cpi_1956=8.46;
	n_cpi_1957=8.19;
	n_cpi_1958=7.97;
	n_cpi_1959=7.91;
	n_cpi_1960=7.78;
	n_cpi_1961=7.70;
	n_cpi_1962=7.62;
	n_cpi_1963=7.52;
	n_cpi_1964=7.43;
	n_cpi_1965=7.31;
	n_cpi_1966=7.11;
	n_cpi_1967=6.89;
	n_cpi_1968=6.62;
	n_cpi_1969=6.27;
	n_cpi_1970=5.93;
	n_cpi_1971=5.68;
	n_cpi_1972=5.51;
	n_cpi_1973=5.19;
	n_cpi_1974=4.67;
	n_cpi_1975=4.28;
	n_cpi_1976=4.05;
	n_cpi_1977=3.80;
	n_cpi_1978=3.53;
	n_cpi_1979=3.17;
	n_cpi_1980=2.79;
	n_cpi_1981=2.53;
	n_cpi_1982=2.39;
	n_cpi_1983=2.30;
	n_cpi_1984=2.21;
	n_cpi_1985=2.13;
	n_cpi_1986=2.09;
	n_cpi_1987=2.03;
	n_cpi_1988=1.94;
	n_cpi_1989=1.86;
	n_cpi_1990=1.76;
	n_cpi_1991=1.69;
	n_cpi_1992=1.64;
	n_cpi_1993=1.59;
	n_cpi_1994=1.55;
	n_cpi_1995=1.51;
	n_cpi_1996=1.47;
	n_cpi_1997=1.43;
	n_cpi_1998=1.41;
	n_cpi_1999=1.38;
	n_cpi_2000=1.34;
	n_cpi_2001=1.3;
	n_cpi_2002=1.28;
	n_cpi_2003=1.25;
	n_cpi_2004=1.22;
	n_cpi_2005=1.18;
	n_cpi_2006=1.14;
	n_cpi_2007=1.11;
	n_cpi_2008=1.07;
	n_cpi_2009=1.07;
	n_cpi_2010=1.06;
	n_cpi_2011=1.02;

	array cpi(1951:2011) n_cpi_1951-n_cpi_2011;
	array hhearns(1951:2011) n_hhearns_1951-n_hhearns_2011;
	array hhearns0206(1951:2011) n_hhearns0206_1951-n_hhearns0206_2011;

	do i = 1951 to 2011;
		hhearns(i) = hhearns(i)*cpi(i);
		hhearns0206(i) = hhearns0206(i)*cpi(i);
	end;

	drop n_cpi_:;

run;
